﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Input;

namespace GrainManage.Tools
{
    public sealed class EventHelper
    {
        /// <summary>
        /// 添加如下事件:
        /// MouseDoubleClick,KeyUp,DropDownClosed
        /// </summary>
        /// <param name="combo"></param>
        /// <param name="queryAction"></param>
        public void AddQueryEventHandler(ComboBox combo, Action queryAction)
        {
            combo.MouseDoubleClick += (sender, e) => queryAction();
            combo.KeyUp += (sender, e) => { if (e.Key == Key.Enter) { queryAction(); } };
            combo.DropDownClosed += (sender, e) => { queryAction(); };
        }

        /// <summary>
        /// 添加如下事件:
        /// MouseDoubleClick,KeyUp,SelectedDateChanged
        /// </summary>
        /// <param name="date"></param>
        /// <param name="queryAction"></param>
        public void AddQueryEventHandler(DatePicker date, Action queryAction)
        {
            date.MouseDoubleClick += (sender, e) => queryAction();
            date.KeyUp += (sender, e) => { if (e.Key == Key.Enter) { queryAction(); } };
            date.SelectedDateChanged += (sender, e) => { queryAction(); };
        }

        public void AddClickEventHandler(Button button, Action clickAction)
        {
            button.Click += (sender, e) => { clickAction(); };
        }

        public void AddDropDownOpenedHandler(ComboBox combo, Action dropDownOpenedAction)
        {
            combo.DropDownOpened += (sender, e) => { dropDownOpenedAction(); };
        }

        public void AddCheckedEventHandler(RadioButton radio, Action checkedAction)
        {
            radio.Checked += (sender, e) => { checkedAction(); };
        }
    }
}
